#define _CRT_SECURE_NO_WARNINGS 1
struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2)
{
    int sum = 0;
    int carry = 0;
    struct ListNode* guard = NULL, * Ptail = NULL;
    guard = Ptail = (struct ListNode*)malloc(sizeof(struct ListNode));
    while (l1 != NULL || l2 != NULL)
    {
        int n1 = l1 ? l1->val : 0;
        int n2 = l2 ? l2->val : 0;
        sum = n1 + n2 + carry;

        struct ListNode* NewNode = (struct ListNode*)malloc(sizeof(struct ListNode));
        NewNode->next = NULL;
        NewNode->val = sum % 10;
        carry = sum / 10;

        Ptail->next = NewNode;
        Ptail = Ptail->next;

        if (l1)
            l1 = l1->next;
        if (l2)
            l2 = l2->next;
    }
    if (carry > 0)
    {
        struct ListNode* NewNode = (struct ListNode*)malloc(sizeof(struct ListNode));
        NewNode->val = carry;
        NewNode->next = NULL;
        Ptail->next = NewNode;
    }
    struct ListNode* Head = guard->next;
    free(guard);
    return Head;
}